package com.water.devtool.define;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.water.devtool.constant.DbType;

@JsonIgnoreProperties(ignoreUnknown = true)
public class DbConfigBean {
	private DbType dbType;
	private String driver;
	private String url;
	private String user;
	private String password;

	private String tableNameLowerCase ="0"; // 表名小写 0 否， 1是
	private String columnNameLowerCase ="0";// 字段名小写 0 否， 1是

	public static DbConfigBean defaultMysql() {
		DbConfigBean conf = new DbConfigBean();
		conf.setDbType(DbType.MYSQL);
		conf.setDriver("com.mysql.jdbc.Driver");
		conf.setUrl("jdbc:mysql://127.0.0.1:3306/device?useUnicode=true&characterEncoding=utf-8");
		conf.setTableNameLowerCase("1");
		conf.setColumnNameLowerCase("0");
		return conf;
	}
	

	public static DbConfigBean defaultPostgreSql() {
		DbConfigBean conf = new DbConfigBean();
		conf.setDbType(DbType.POSTGRESQL);
		conf.setDriver("org.postgresql.Driver");
		conf.setUrl("jdbc:postgresql://127.0.0.1:5432/XXX?disableColumnSanitiser=true&useUnicode=true&characterEncoding=utf-8");
		conf.setTableNameLowerCase("1");
		conf.setColumnNameLowerCase("1");
		return conf;
	}


	public static DbConfigBean defaultOracle() {
		DbConfigBean conf = new DbConfigBean();
		conf.setDbType(DbType.ORACLE);
		conf.setDriver("oracle.jdbc.driver.OracleDriver");
		conf.setUrl("jdbc:oracle:thin:@127.0.0.1:1521:orcl");
		conf.setTableNameLowerCase("0");
		conf.setColumnNameLowerCase("0");
		return conf;
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public DbType getDbType() {
		return dbType;
	}

	public void setDbType(DbType dbType) {
		this.dbType = dbType;
	}

	@JsonIgnore
	public String getContent() {
		StringBuilder str = new StringBuilder();
		str.append("driver = ").append(getDriver()).append("\r\n");
		str.append("url =  ").append(getUrl()).append("\r\n");
		str.append("user = ").append(getUser()).append("\r\n");
		str.append("password = ").append(getPassword()).append("\r\n");
		str.append("tableNameLowerCase = ").append(getTableNameLowerCase()).append("\r\n");
		str.append("columnNameLowerCase = ").append(getColumnNameLowerCase()).append("\r\n");
		return str.toString();

	}

	public String getTableNameLowerCase() {
		return tableNameLowerCase;
	}

	public void setTableNameLowerCase(String tableNameLowerCase) {
		this.tableNameLowerCase = tableNameLowerCase;
	}

	public String getColumnNameLowerCase() {
		return columnNameLowerCase;
	}

	public void setColumnNameLowerCase(String columnNameLowerCase) {
		this.columnNameLowerCase = columnNameLowerCase;
	}

}
